package com.huazhi.wzsnw.timer;



import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.huazhi.wzsnw.mapper.LinedMapper;
import com.huazhi.wzsnw.model.Lined;
import org.apache.http.HttpEntity;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * description: add a description
 *
 * @author Zhengch
 * @version 1.0.0
 * @date 2022/09/21 15:31:39
 */
@Component
public class SxtlxGl {
   @Autowired
   private LinedMapper linedMapper;


   public static final String Token = "at.7co9ludn5yuwho0ubdjy6rrrdvfl56lw-4n6vly93e4-0exi7p6-irqragnzy";

    public  void  startUpdateVideo(){
    for (int i = 0;i<5;i++){
       updateStaet(i);
    }
    }

    /*
     * description 更新摄像头状态
     * @author Zhengch
     * @date 2022/9/21 15:38
     * @version 1.0.0
     * @param null
     * @return null
     */

    public  void  updateStaet(int page)  {
        try {
            HttpPost post = new HttpPost("https://open.ys7.com/api/lapp/device/list");
            List<BasicNameValuePair> basicNameValuePairList = new ArrayList<BasicNameValuePair>();
            basicNameValuePairList.add(new BasicNameValuePair("accessToken",Token));
            basicNameValuePairList.add(new BasicNameValuePair("pageStart",String.valueOf(page)) );
            basicNameValuePairList.add(new BasicNameValuePair("pageSize","50"));
            post.setEntity(new UrlEncodedFormEntity(basicNameValuePairList,"utf-8"));
            CloseableHttpClient client = HttpClients.createDefault();
            CloseableHttpResponse response = client.execute(post);
            HttpEntity entity = response.getEntity();
            //获得请求结果转成String
            String result = EntityUtils.toString(entity);
            //转成jsonObject遍后续操作
            JSONObject jsonObject = JSON.parseObject(result);
            JSONArray jsonArray = jsonObject.getJSONArray("data");
            for (int i = 0;i<jsonArray.size();i++){
                JSONObject item = (JSONObject) jsonArray.get(i);
                String deviceSerial = item.getString("deviceSerial");
                Integer status = item.getInteger("status");
                linedMapper.updateSxtztByVideoId(status,deviceSerial);
                System.out.println("编号为："+deviceSerial+"摄像头状态已经更新！");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public void sxtqscz(){
        String str = "E38253679," +
                "E42012625," +
                "E42012633," +
                "E42012634," +
                "E45494686," +
                "E45494687," +
                "E45494688," +
                "E45494689," +
                "E46103442," +
                "E50014672," +
                "E50014675," +
                "E50014676," +
                "E54381734," +
                "E59772797," +
                "E68120167," +
                "E68120169," +
                "E69013751," +
                "E69013763," +
                "E69013767," +
                "E69013782," +
                "F49181454," +
                "F31775335," +
                "F49181424," +
                "F49181434," +
                "F49181443," +
                "F49181427," +
                "F49181455," +
                "F69453436," +
                "F75624861," +
                "F75624864," +
                "F75624866," +
                "E45494702," +
                "F75953060," +
                "F75953067," +
                "F75624872," +
                "F75953069," +
                "F75953095," +
                "F75953099," +
                "E36181467," +
                "E36181463," +
                "E36181459," +
                "E46103446," +
                "E45494704," +
                "E38253680," +
                "E36181465," +
                "E53181396," +
                "E69013794," +
                "E38253686," +
                "E58026321," +
                "E82737234," +
                "F49181436," +
                "F75953109," +
                "E59772800," +
                "F45494703," +
                "F75624870," +
                "F75953106," +
                "F75953057," +
                "F31775327," +
                "F49181445," +
                "E38253681," +
                "E45494690," +
                "F49181438," +
                "E45494696," +
                "F46457578," +
                "F75953070," +
                "E58026332," +
                "F49181460," +
                "E36181473," +
                "E68120162," +
                "E36181460," +
                "E38253693," +
                "E38253695," +
                "E46103447," +
                "E53181429," +
                "F31775332," +
                "F31775334," +
                "F31775345," +
                "F31775354," +
                "E36181466," +
                "E38253694," +
                "E50014660," +
                "E59772792," +
                "F31775323," +
                "E36181471," +
                "J96214891," +
                "J96214949," +
                "J96214931," +
                "J96214963," +
                "J96214906," +
                "J96214966," +
                "F75953112," +
                "F32119421," +
                "E68120166," +
                "E46103455," +
                "F75953089," +
                "F31775355," +
                "E38253689," +
                "E50014664," +
                "F31775326," +
                "F49181426," +
                "F69453448," +
                "J96214898," +
                "E50014669," +
                "E58026320," +
                "F49181435," +
                "F49181439," +
                "F75953100," +
                "E59772799," +
                "E38253696," +
                "F31775322," +
                "E38253691," +
                "E38253698," +
                "E82737280," +
                "F49181422," +
                "F75624877," +
                "E42012624," +
                "E50014667," +
                "E53181432," +
                "E45494694," +
                "E58026310," +
                "E59772804," +
                "E59772809," +
                "E68120163," +
                "F49181448," +
                "J96214896," +
                "E07965062," +
                "E45494701," +
                "E45494692," +
                "E45494693," +
                "E45494697," +
                "E50014658," +
                "E68120159," +
                "F31775346," +
                "F31775350," +
                "F75624888," +
                "F69453404," +
                "F75953068," +
                "E38253683," +
                "F69453405," +
                "F46457581," +
                "E36181474," +
                "F75953107," +
                "E50014665," +
                "E38253688," +
                "F75953078," +
                "E38253685," +
                "E38253690," +
                "E50014662," +
                "F31775328," +
                "F31775338," +
                "F46457575," +
                "E38253692," +
                "E38253687," +
                "F75953080," +
                "E82737263," +
                "E50014674," +
                "E53181443," +
                "E07965057," +
                "E38253684," +
                "E45494691," +
                "F75953093," +
                "F69453427," +
                "F31775325," +
                "F43943868," +
                "F49181440," +
                "J96214902," +
                "J96214928";
        String[] strings = str.split(",");
        for (String videoTid:strings){
            Lined lined = linedMapper.selectByVideoTid(videoTid);
            if(lined == null){
                System.out.println("编号为："+videoTid+"摄像头缺失");
            }
        }
    }
}
